package com.zqxq.lottery.entity.vo.jczq;

import com.zqxq.common.utils.DateUtils;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.entity.enums.LotteryIdEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 说    明：   app API 赛事信息
 * 创 建 人：	一刀·胡
 * 创建时间：	2018/5/4 13:58
 * 修 改 人：
 * 修改日期：
 **/
@Data
@ApiModel
public class MatchApiVO1 {
    @ApiModelProperty("彩种")
    private Long lotteryId = LotteryIdEnum.JCZQ.getId();//彩种
    @ApiModelProperty("赛事日期")
    private String date;//赛事日期
    @ApiModelProperty("赛事周期（星期几）")
    private String week;//赛事周期（星期几）
    @ApiModelProperty("赛事数量")
    private Integer count = 0;//赛事数量
    @ApiModelProperty("赛事信息集合")
    private List<MatchVO> match;//	赛事信息集合

    public MatchApiVO1(){}

    public MatchApiVO1(String code){
        if (StrUtils.isEmpty(code)){
            this.date = "今日";
            this.week = "";
        }else {
            String c = String.valueOf(code.charAt(8));
            String date = code.substring(0,4)+"-"+code.substring(4,6)+"-"+code.substring(6,8);

            if (c.equals(getWeek("",1))){
                this.date = "今日";
                this.week = "";
            }else{
                this.date = date;
                this.week = getWeek(date,2);
            }
        }
    }
    public static String getWeek(String strDate,Integer type) {
        String[] weekIndex = {"7","1","2","3","4","5","6"};
        String[] week = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        Date date = new Date();
        if (StrUtils.isNotEmpty(strDate)){
            date = DateUtils.strToDate(strDate,"yyyy-MM-dd");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int i = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (i<0){
            i = 0;
        }
        if (type == 1){
            return weekIndex[i];
        }else {
            return week[i];
        }

    }


    public static void main(String[] args) {
        MatchApiVO1 matchApiVO1 = new MatchApiVO1("201808186");
        matchApiVO1.getWeek();
        matchApiVO1.getDate();
        System.out.println(matchApiVO1.getWeek()+"======"+matchApiVO1.getDate());
    }

}
